<?php
$id=$_REQUEST['id'];
$flag=$_REQUEST['flag'];

$link=new mysqli('127.0.0.1','root','root','books_manage_system','3306');
if($link->connect_error){
    die('连接失败'.$link->connect_error);
}else{
    //连接成功，设置编码格式
    mysqli_set_charset($link,'utf8');
    $link->query('SET NAMES UTF8');

    //存储数据
    $result=array();
    $result['data']=array();

   if($flag=='users'){
        $sql="select * from users";
        $re=$link->query($sql);
        $num=mysqli_num_rows($re);
        if($num>0){
            // 遍历数据  存储在$reuslt
            while($rows = $re->fetch_assoc()) {
                $result['status']='success';
                array_push($result['data'],$rows);
            }
        }else{
            $result['status']='fail';
        }
   }else{
        $sql="select * from users where id='$id'";
        $re=$link->query($sql);
        $row=mysqli_fetch_assoc($re);
        if($row>0){
            //  存储在$reuslt
            $result['status']='success';
            array_push($result['data'],$row);
        }else{
            $result['status']='fail';
            $result['message']='当前书籍暂未借阅';
        }
   }
    mysqli_free_result($re); //释放结果集
    //关闭数据库
    $link->close();
    die(json_encode($result));
    }
?>